<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-4-22
 * Time: 下午1:12
 */
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
$plugin_iexam = DB::TABLE('plugin_iexam');
$plugin_iexam_category = DB::TABLE('plugin_iexam_category');
$sql = <<<EOF
DROP TABLE IF EXISTS `$plugin_iexam_category`;
CREATE TABLE `$plugin_iexam_category` (
  `catid` int(11) NOT NULL AUTO_INCREMENT,
  `upid` int(11) DEFAULT '0' COMMENT '上级ID',
  `catname` varchar(100) DEFAULT NULL COMMENT '试题分类名称',
  `weight` decimal(3,2) DEFAULT NULL COMMENT '试题权重',
  `displayorder` int(11) DEFAULT '0' COMMENT '排序',
  `description` text COMMENT '分类说明',
  PRIMARY KEY (`catid`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `$plugin_iexam`;
CREATE TABLE `$plugin_iexam` (
  `eid` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) DEFAULT NULL COMMENT '所属分类',
  `tid` int(11) NOT NULL COMMENT '论坛帖子PID',
  `pid` int(11) NOT NULL COMMENT '帖子正文PID',
  `title` varchar(250) NOT NULL COMMENT '考试题目',
  `type` varchar(20) DEFAULT NULL COMMENT '试题类型',
  `question` text COMMENT '试题答案',
  `displayorder` int(11) DEFAULT '0' COMMENT '显示顺序',
  `description` text COMMENT '试题说明',
  `score` int(11) NOT NULL DEFAULT '0' COMMENT '试题分数',
  PRIMARY KEY (`eid`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
EOF;
$sql = str_replace("\r\n", "\n", $sql);
runquery($sql);

$data = <<<EOF
INSERT INTO `$plugin_iexam_category` (`upid`, `catname`, `weight`, `displayorder`, `description`) VALUES
  (0, 'TE1332系统知识试题库', 0.4, 0, 'TE1332系统知识试题库'),
  (0, '微量元素知识及应用试题库', 0.6, 0, '微量元素知识及应用试题库');
EOF;

$conf = $_G[config]['db'][1];
$link = mysql_connect($conf['dbhost'], $conf['dbuser'], $conf['dbpw']);
mysql_set_charset($conf['dbcharset'], $link);
mysql_select_db($conf['dbname'], $link) or die ('Can\'t use foo : ' . mysql_error());
mysql_query($data, $link)
or die("Invalid query: " . mysql_error());
mysql_close($link);
$finish = TRUE;